package kursy_walut_NBP;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;

import nbpservice.NbpServiceImpl;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.xml.sax.SAXException;

import view.ConsoleView;
import view.SwingView;
import controler.Controler;
import controler.ControlerImpl;
import dao.CrudService;
import dao.CrudServiceImpl;
import entities.Currency;
import entities.ExchangeRate;
import exceptions.NoSuchCurrencyException;
import exceptions.NoSuchDocumentException;

public class MainNbp 
{
	static CrudService crud_service = new CrudServiceImpl();
	static SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");

	public static void main(String[] args) throws NoSuchDocumentException, IOException, SAXException, ParserConfigurationException, ParseException, NoSuchCurrencyException
	{
		
		
		
		
	}
	
	
	static void fillExamples() throws ParseException
	{
		
		Currency ora = new Currency("ORA", "Orzech1");
		Currency orb = new Currency("ORB", "Orzech2");
		Currency orc = new Currency("ORC", "Orzech3");
		Currency orz = new Currency("ORZ", "OrzechZ");
		
		crud_service.addCurrency(ora);
		crud_service.addCurrency(orb);
		crud_service.addCurrency(orc);
		crud_service.addCurrency(orz);
		
		crud_service.addExchangeRate(new ExchangeRate(sdf.parse("2014-12-17"), orz, 1, new BigDecimal(3)));
		crud_service.addExchangeRate(new ExchangeRate(sdf.parse("2014-12-17"), ora, 1, new BigDecimal(3)));
		crud_service.addExchangeRate(new ExchangeRate(sdf.parse("2014-11-17"), orb, 1, new BigDecimal(9)));
		crud_service.addExchangeRate(new ExchangeRate(sdf.parse("2014-10-12"), orz, 1, new BigDecimal(19)));
	}
	
	static void show()
	{
		CrudService crud_service = new CrudServiceImpl();
		System.out.println(crud_service.readAllCurrencies());
		System.out.println(crud_service.readAllExchangeRates());
	}
	
	
	public static void example() throws NoSuchDocumentException, IOException, SAXException, ParserConfigurationException, ParseException, NoSuchCurrencyException
	{
		System.out.println(new NbpServiceImpl().getNewestExchangeRateForGivenCurrencyCode("GBP"));
		System.out.println(new NbpServiceImpl().getNewestDecimalExchangeRateForGivenCurrencyCode("GBP"));
	}

	private static void ConsoleModeRun()
	{
		Controler controler = new ControlerImpl(new NbpServiceImpl(), new ConsoleView());
		controler.start();
	}
	
	private static void SwingModeRun()
	{
		Controler controler = new ControlerImpl(new NbpServiceImpl(), new SwingView());
		controler.start();
	}

}
